﻿/**
 * Created by Richard Radlherr.
 * Date: 02.07.2006 09:59
 */

using System;
using TagTool.Core;
using TagTool.GraphicTypes;
using CsGL.OpenGL;

namespace TagTool.Nodes.Graphic
{

	public class Projector2 : RenderableNode
	{
		private InputSlot scene;
		private InputSlot shape;
		private InputSlot cursor;
		private InputSlot selected;
		
        private InputSlot fullScreen;

		IStage stage;

		private static int count = 0;

		public Projector2()
		{
			count ++;
			Name = "Projector" + count.ToString();
			scene = new InputSlot(this, "Scene", new Shape());
			shape = new InputSlot(this, "Actual shape", new Shape());
			cursor = new InputSlot(this, "Cursor", new Shape());
			selected = new InputSlot(this, "Selected", new Shape());
			((Shape)selected.Value).Update();
			
            fullScreen = new InputSlot(this, "Fullscreen", false);
			stage = ProjectManager.Instance.CreateStage(Name);
			stage.Resize((count - 1) * 300, 0, 300, 300);
			stage.Content = this;
		}
		
		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot Scene
		{
			get { return scene; }
		}
		
		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot Shape
		{
			get { return shape; }
		}

		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot Cursor
		{
			get { return cursor; }
		}
		
		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot Selected
		{
			get { return selected; }
		}

		[NodeAttribute(SlotType.Input, Show = true)]
        public InputSlot Fullscreen
        {
            get { return fullScreen; }
        }
		
		public override void Update(Object sender)
		{
            stage.FullScreen = (bool)fullScreen.Value;
            //((Cursor)cursor.Value).Initialize();
            Render();
			CastTrigger();
		}
		
		public override bool FullScreen
        {
			get { return stage.FullScreen; }
			set { stage.FullScreen = value; }
        }
		
		public override void Render()
	 	{ 
			CsGL.OpenGL.GL.glPolygonMode(CsGL.OpenGL.GL.GL_FRONT_AND_BACK, CsGL.OpenGL.GL.GL_FILL);
			
			// only move the content of the scene not the actually drawn shape nad cursor
			((Shape)scene.Value).Move();
			((Shape)scene.Value).Render();
			
			((Shape)shape.Value).Render();
			((Shape)cursor.Value).Render();
			
			CsGL.OpenGL.GL.glPolygonMode(CsGL.OpenGL.GL.GL_FRONT_AND_BACK, CsGL.OpenGL.GL.GL_LINE);
			((Shape)selected.Value).Render();
	 	}
	}
}
